package com.demoku.web.application.test.impl;

import java.util.List;

import javax.inject.Named;

import org.iff.infra.util.BeanHelper;
import org.iff.infra.util.MapHelper;
import org.iff.infra.util.mybatis.plugin.Page;
import org.iff.infra.util.mybatis.service.Dao;
import org.springframework.transaction.annotation.Transactional;

import com.demoku.web.application.test.FfApplication;
import com.demoku.web.application.test.vo.FfVO;
import com.demoku.web.domain.test.Ff;

/**
 * @author autoCode
 */
@Named("ffApplication")
@Transactional
public class FfApplicationImpl implements FfApplication {

	@Override
	public void removeFf(String ffId) {
		Ff.remove(ffId);
	}

	@Override
	public FfVO saveFf(FfVO vo) {
		Ff a = new Ff();
		BeanHelper.copyProperties(a, vo);
		a.save();
		FfVO copyProperties = BeanHelper.copyProperties(new FfVO(), a);
		return copyProperties;
	}

	@Override
	public FfVO getFfVO(String ffId) {
		return BeanHelper.copyProperties(new FfVO(), Ff.get(ffId));
	}

	@Override
	public List<FfVO> findAll(Page pages) {
		List<Ff> list = Dao.queryList("Ff_Mapping.findAll",
				MapHelper.toMap("page", pages));
		pages.setRows(list);
		return pages.toPage(FfVO.class).getRows();
	}

	@Override
	public Page pageFindAll(Page pages) {
		List<Ff> list = Dao.queryList("Ff_Mapping.findAll",
				MapHelper.toMap("page", pages));
		pages.setRows(list);
		return pages.toPage(FfVO.class);
	}
	
	@Override
	public Page pageFindAllFf(FfVO vo) {
		Page pages = Page.pageable(10, 1, 0, null);
		
		List<Ff> list = Dao.queryList("Ff_Mapping.pageFindFf",
				MapHelper.toMap("page", pages ));
		pages.setRows(list);
		return pages.toPage(FfVO.class);
	}

}
